package com.baimifan.renovation.adapter;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.baimifan.renovation.R;
import com.baimifan.renovation.model.DemoData;
import com.baimifan.renovation.view.DemoFragHolder;

import org.xutils.x;

import java.util.ArrayList;

/**
 * Created by sunyuanfei on 2017/7/7.
 */

public class DemoCardAdapter extends RecyclerView.Adapter<DemoFragHolder> {
    private ArrayList<DemoData> mlist;
    private Float w, h;

    public DemoCardAdapter (ArrayList<DemoData> list, Float w, Float h) {
        this.mlist = list;
        this.w = w;
        this.h = h;
    }
    @Override
    public DemoFragHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.democard_item, parent, false);
        DemoFragHolder demoFragHolder = new DemoFragHolder(view);
        return demoFragHolder;
    }

    @Override
    public void onBindViewHolder(DemoFragHolder holder, int position) {
        holder.cardView.setContentPadding(2,2,2,2);
        holder.cardView.setCardElevation(7);
        holder.cardView.setCardBackgroundColor(Color.WHITE);

        LinearLayout.LayoutParams params_card = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        if (position == 0 || position == 1) {
            params_card.setMargins((int)(w*2), (int)(h*9),0, 0);
        } else {
            params_card.setMargins((int)(w*2), (int)(h*12),0, 0);
        }
        holder.cardView.setLayoutParams(params_card);
        LinearLayout.LayoutParams params_iv = new LinearLayout.LayoutParams((int)(w*172), (int)(h*98));
        holder.iv.setLayoutParams(params_iv);
        LinearLayout.LayoutParams params_tv = new LinearLayout.LayoutParams((int)(w*172),
                ViewGroup.LayoutParams.WRAP_CONTENT);
        holder.title.setLayoutParams(params_tv);
        holder.title.setPadding((int)(w*19), (int)(h*7), (int)(w*27), (int)(h*8));
        holder.title.setText(mlist.get(position).getTitle());
        x.image().bind(holder.iv, mlist.get(position).getImg());
    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }
}
